'use strict';

var express = require('express');
var controller = require('./article.controller');
var auth = require('../../auth/auth.service');
var multer = require('multer');
var upload = multer({dest: 'uploads/'});

var router = express.Router();

// 文章相关
// 增
router.post('/addArticle', auth.hasRole('admin'), controller.addArticle);
router.post('/addProcess', auth.isAuthenticated(), controller.addProcess);
// 删
// router.delete('/article/:id', auth.hasRole('admin'), controller.destroy);
// router.delete('/process/:id', auth.isAuthenticated(), controller.destroyProcess);
// 改
// router.put('/:id/updateArticle', auth.hasRole('admin'), controller.updateArticle);
// router.put('/:id/updateProcess', auth.hasRole('admin'), controller.updateProcess);
// 查
router.get('/getArticleList', controller.getArticleList);
router.get('/getProcessList', controller.getProcessList);
router.get('/getArticle/:id', controller.getArticle);
router.get('/getProcess/:id', controller.getProcess);


//前台获取
router.get('/getFrontArticleList', controller.getFrontArticleList);
router.get('/getFrontArticleCount', controller.getFrontArticleCount);
router.get('/:id/getFrontArticle', controller.getFrontArticle);
// 图片相关
router.post('/fetchImage', auth.hasRole('admin'), controller.fetchImage); // 获取网络图片
router.get('/getIndexImage', controller.getIndexImage);
router.post('/uploadImage', auth.isAuthenticated(), upload.single('file'), controller.uploadImage);
//用户喜欢文章
router.put('/:id/toggleLike', auth.isAuthenticated(), controller.toggleLike);
//获取上一篇和下一篇
router.get('/:id/getPrenext', controller.getPrenext);
module.exports = router;
